package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.ThirdPartyApiService;
import com.yixun.qfbao.apidto.SendValidateCodeForPwdReqDto;
import com.yixun.qfbao.apidto.SendValidateCodeForPwdResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.dto.CompanyDto;
import com.yixun.qfbao.service.CompanyService;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.SendValidateCodeForPwdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Date 2017/12/1
 * @Author sangtao
 * @Computer Administrator
 */
@Service("sendValidateCodeForPwdHander")
public class SendValidateCodeForPwdHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(SendValidateCodeForPwdHander.class);
    @Autowired
    ThirdPartyApiService thirdPartyApiService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        SendValidateCodeForPwdReqVo req = (SendValidateCodeForPwdReqVo)reqDto;
        SendValidateCodeForPwdReqDto sendValidateCodeForPwdReqDto = req.getParams();
        BaseResponseDTO<SendValidateCodeForPwdResDto> res = new BaseResponseDTO<SendValidateCodeForPwdResDto>();
        SendValidateCodeForPwdResDto resDto = new SendValidateCodeForPwdResDto();
        try {
            resDto = thirdPartyApiService.sendValidateCodeForPwd(sendValidateCodeForPwdReqDto);

            resDto.setResult(ResultEnum.SUCCESS.getNo());
            resDto.setResultMsg("发送成功");
        } catch (TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(e.getMessage());
        }
        catch (Exception e) {
            logger.error("SendValidateCodeForPwdHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("发送失败!");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        res.setErrorMsg(resDto.getResultMsg());
        return res;
    }
}
